/**
 * 
 */
package org.ranch.web.midlet;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * @author Jmpango
 * 
 */
public class MidletUser {
    /**
     * 
     */
    private String username;
    private String password;
    private String status;

    public MidletUser() {
	super();
    }

    public MidletUser(String username, String password, String status) {
	setUsername(username);
	setPassword(password);
	setStatus(status);
    }

    /**
     * @return the username
     */
    public String getUsername() {
	return username;
    }

    /**
     * @param username
     *            the username to set
     */
    public void setUsername(String username) {
	this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
	return password;
    }

    /**
     * @param password
     *            the password to set
     */
    public void setPassword(String password) {
	this.password = password;
    }
    
    

    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }

    public byte[] serializer() throws IOException {
	
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	DataOutputStream dos = new DataOutputStream(baos);
	
	dos.writeUTF(getStatus());
	dos.writeUTF(getUsername());
	dos.writeUTF(getPassword());
	dos.flush();

	dos.close();
	baos.close();

	return baos.toByteArray();
    }

    public MidletUser deserializer(byte[] b) throws IOException, ClassNotFoundException {
	ByteArrayInputStream bais = new ByteArrayInputStream(b);
	DataInputStream dis = new DataInputStream(bais);
	this.setUsername(dis.readUTF());
	this.setPassword(dis.readUTF());

	bais.reset();
	dis.close();
	bais.close();
	return this;
    }
}
